package com.cby.widget.sample

import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.cby.widget.lib.bullet.LaneView
import com.cby.widget.lib.kotlin.*

/**
 * @description: LaneViewActivity
 *
 * @author ChenBaoyang
 * @date 2021/10/2 15:57
 */
class LaneViewActivity : AppCompatActivity() {

    private lateinit var laneView: LaneView
    //dsl
    private val contentView by lazy{
        ConstraintLayout {
            tag = "lanview"
            layout_width = match_parent
            layout_height = 200

            TextView {
                layout_id = "tvFansDefalutKonledge"
                layout_width = wrap_content
                layout_height = wrap_content
                textSize = 16f
                textColor = "#3F4658"
                gravity = gravity_center
                text = "1234567891234567"
                maxEms = 3
                isSingleLine = true
                ellipsize = ellipsize_end
                top_toTopOf = parent_id
                center_horizontal = true
            }

            laneView = LaneView(context).apply {
                layout_id = "lanview"
                layout_width = match_parent
                layout_height = 200
                top_toBottomOf = "tvFansDefalutKonledge"
                bottom_toBottomOf = parent_id
                background_color = "#00ff00"
                verticalGap = 5
                horizontalGap = 10
                speedMode = LaneView.Speed.Sync
                loopMode = LaneView.Loop.Forever
                duration = 3000L
                createView = {
                    TextView(autoAdd = false) {
                        layout_id = "tv"
                        layout_width = wrap_content
                        layout_height = wrap_content
                        gravity = gravity_center
                        textSize = 20f
                        text = "asdf"
                        padding_start = 12
                        padding_bottom = 5
                        padding_end = 12
                        padding_top = 5
                        shape = shape {
                            corner_radius = 25
                            solid_color = "#80c0c0c0"
                        }
                    }
                }
                bindView = { data, view ->
                    (data as? String)?.let {
                        view.find<TextView>("tv")?.text = it
                    }
                }
            }.also {
                addView(it)
            }
        }
    }

    private val laneBeans = listOf(
        "1",
        "2",
        "3",
        "4",
        "5 ",
        "6",
        "7",
        "8",
        "9",
        "11",
        "22",
        "33",
        "44",
        "55",
        "66",
        "77",
        "88",
        "99",
        "111",
        "222",
        "333",
        "444",
        "555",
        "666",
        "777"
    )

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(contentView)

        laneView.show(laneBeans)
    }
}